/**
 * 生成UUID
 */
exports.UUID = () => {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

/**
 * 产生随机数函数
 * @param {*} n 
 */
exports.randomNumber = (n) => {
    var rnd = "";
    for (var i = 0; i < n; i++)
        rnd += Math.floor(Math.random() * 10);
    return rnd;
}

/**
 * 生成超级权限密码
 */
exports.superPassword = () => {
    var date = new Date()
    return "01" + date.getFullYear() + (date.getMonth() + 1).toString() + date.getDay()
}

/**
 * 日期选择器 -- 数据源
 * @param {*} startYear 
 * @param {*} endYear 
 * @param {*} date 
 */
exports.dateTimePickerDataSource = (startYear, endYear, date) => {
    // 返回默认显示的数组和联动数组的声明
    var dateTime = [],
        dateTimeArray = [
            [],
            [],
            [],
            [],
            [],
            []
        ];
    var start = startYear || 1978;
    var end = endYear || 2100;
    // 默认开始显示数据
    var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();
    // 处理联动列表数据
    /*年月日 时分秒*/
    dateTimeArray[0] = getLoopArray(start, end);
    dateTimeArray[1] = getLoopArray(1, 12);
    dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
    dateTimeArray[3] = getLoopArray(0, 23);
    dateTimeArray[4] = getLoopArray(0, 59);
    dateTimeArray[5] = getLoopArray(0, 59);

    dateTimeArray.forEach((current, index) => {
        dateTime.push(current.indexOf(defaultDate[index]));
    });

    return {
        dateTimeArray: dateTimeArray,
        dateTime: dateTime
    }
}